using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DotDAO
/// </summary>
public class DotDAO:DataProvider
{
    public ArrayList LayMang_Dot()
    {
        connect();
        ArrayList arr = new ArrayList();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Select_Dot", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                DotDTO ddto = new DotDTO();
                ddto.MaDot = dr.GetInt32(0);
                ddto.NamThucHien = dr.GetInt32(1);
                ddto.ThangThucHien = dr.GetInt32(2);
                ddto.NgayHetHan = dr.GetDateTime(3);                
                arr.Add(ddto);
            }
        }
        catch (Exception es)
        {
            throw es;
        }
        return arr;
    }
    public void insert(DotDTO ddto)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Insert_Dot", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@namthuchien", SqlDbType.Int);
            cmd.Parameters["@namthuchien"].Value = ddto.NamThucHien;
            cmd.Parameters["@namthuchien"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@thangthuchien", SqlDbType.Int);
            cmd.Parameters["@thangthuchien"].Value = ddto.NamThucHien;
            cmd.Parameters["@thangthuchien"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ngayhethan", SqlDbType.DateTime);
            cmd.Parameters["@ngayhethan"].Value = ddto.NamThucHien.ToString();
            cmd.Parameters["@ngayhethan"].Direction = ParameterDirection.Input;
            

            cmd.ExecuteNonQuery();
        }
        catch (Exception es)
        {
            throw es;
        }
    }
    public void update(DotDTO ddto)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Update_Dot", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@madot", SqlDbType.Int);
            cmd.Parameters["@madot"].Value = ddto.MaDot;
            cmd.Parameters["@madot"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@namthuchien", SqlDbType.Int);
            cmd.Parameters["@namthuchien"].Value = ddto.NamThucHien;
            cmd.Parameters["@namthuchien"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@thangthuchien", SqlDbType.Int);
            cmd.Parameters["@thangthuchien"].Value = ddto.NamThucHien;
            cmd.Parameters["@thangthuchien"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ngayhethan", SqlDbType.SmallDateTime);
            cmd.Parameters["@ngayhethan"].Value = ddto.NgayHetHan.ToString();
            cmd.Parameters["@ngayhethan"].Direction = ParameterDirection.Input;            

            cmd.ExecuteNonQuery();
        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }
	
	public DotDAO()
	{
		//
		// TODO: Add constructor logic here
		//
	}
}
